import Base from 'models/base';

export default class ReleaseCircle extends Base {
  typeTag = '';
  themeData = '';
  themeText = '';
  content = '';
  uploadType = 'pic';
  video = '';
  pics = [];

  constructor(location) {
    super();

    let lnglat = location.lnglat;
    this.longitude = lnglat.lng;
    this.latitude = lnglat.lat;
    this.location = location.locationData.address;
  }

  checkValid() {
    if (this.typeTag === '') {
      return 'typeTag';
    }

    let content = this.content.trim();
    if (content === '') {
      if (this.uploadType === 'pic') {
        if (this.pics.length === 0) {
          return 'noContent';
        }
      } else {
        if (this.video === '') {
          return 'noContent';
        }
      }
    }

    let themeData = this.themeData;
    if (themeData === '') {
      return 'theme';
    }

    if (themeData === 'default') {
      if (this.themeText.trim() === '') {
        return 'themeText';
      }
    }

    return '';
  }

  getObject() {
    let postData = {
      typeTag: JSON.stringify([this.typeTag]),
      location: this.location,
      longitude: this.longitude,
      latitude: this.latitude
    };

    let content = this.content;
    if (content !== '') {
      
      postData.content = content;
    }

    if (this.uploadType === 'pic') {
      let pics = this.pics;
      if (pics.length > 0) {
        postData.pics = JSON.stringify(pics);
      }
    } else {
      let video = this.video;
      if (video !== '') {
        postData.videos = JSON.stringify([video]);
      }
    }

    let themeData = this.themeData;
    if (themeData !== 'default') {
      postData.themeTag = JSON.stringify([themeData.text]);
    } else {
      postData.themeTag = JSON.stringify([this.themeText]);
    }

    return postData;
  }
}
